package models.dao;

import java.sql.ResultSet;
import java.util.ArrayList;

import model.pojo.Currency;
import model.util.MySqlDataAccessHelper;

public class CuryDAO {
	
	public ArrayList<Currency> curylst(){
		ArrayList<Currency> lst = new ArrayList<Currency>();
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try{
			mysql.open();
			String ten="DescVN";
			String sql ="select CuryID,"+ten+" from currency";
			ResultSet rs=mysql.executeQuery(sql);
			Currency cg;
			while(rs.next()){
				cg = new Currency();
				cg.setCuryID(rs.getString("CuryID"));
				cg.setCurname(rs.getString(ten));
			}
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return lst;
	}
	
	public ArrayList<Currency> onecury(String id){
		ArrayList<Currency> lst = new ArrayList<Currency>();
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try{
			mysql.open();
			String ten="DescVN";
			String sql ="select CuryID,"+ten+" from currency where CuryID='"+id+"'";
			ResultSet rs=mysql.executeQuery(sql);
			Currency cg;
			while(rs.next()){
				cg = new Currency();
				cg.setCuryID(rs.getString("CuryID"));
				cg.setCurname(rs.getString(ten));
				cg.setRateExchange(rs.getFloat("RateExchange"));
			}
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return lst;
	}
}
